$(document).ready(function () {

	var tablelist = [
		{
			"protoName": "proto_a",
			"num": "4",
			"size": "512KB",
			"describe": "航迹",
			"ID": "0"
		},
		{
			"protoName": "proto_b",
			"num": "2",
			"size": "512KB",
			"describe": "航迹",
			"ID": "1"
		},
		{
			"protoName": "proto_c",
			"num": "3",
			"size": "512KB",
			"describe": "测试",
			"ID": "2"
		},
		{
			"protoName": "proto_d",
			"num": "5",
			"size": "512KB",
			"describe": "测试",
			"ID": "3"
		},
	]



	$("#table_page").bootstrapTable({
		//url: '',
		data: tablelist,
		dataType: 'json',
		//method: 'POST',                      //请求方式（*）
		//toolbar: '#toolbar',              //工具按钮用哪个容器
		striped: true,                      //是否显示行间隔色
		cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pagination: true,                   //是否显示分页（*）
		sortable: true,                     //是否启用排序
		sortOrder: "asc",                   //排序方式
		sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
		pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
		pageSize: 10,                     //每页的记录行数（*）
		pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
		search: true,                      //是否显示表格搜索
		strictSearch: true,
		showColumns: true,                  //是否显示所有的列（选择显示的列）
		showRefresh: true,                  //是否显示刷新按钮
		showExport: true,
		Icons: 'glyphicon-export icon-share',
		minimumCountColumns: 1,             //最少允许的列数
		clickToSelect: true,                //是否启用点击选中行
		//height: 500,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
		uniqueId: "name",                     //每一行的唯一标识，一般为主键列
		//showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
		cardView: false,                    //是否显示详细视图
		detailView: false,                  //是否显示父子表
		//得到查询的参数
		queryParams: function (params) {
			//这里的键的名字和控制器的变量名必须一致，这边改动，控制器也需要改成一样的
			var temp = {
				rows: params.limit,                         //页面大小
				page: (params.offset / params.limit) + 1,   //页码
				sort: params.sort,      //排序列名  
				sortOrder: params.order //排位命令（desc，asc） 
			};
			return temp;
		},

		columns: [{
			field: 'protoName',
			title: '协议名称'
		}, {
			field: 'num',
			title: '条目数量'
		}, {
			field: 'size',
			title: '占用容量'
		}, {
			field: 'describe',
			title: '描述'
		}, {
			field: 'ID',
			title: '查看',
			width: 120,
			align: 'center',
			valign: 'middle',
			formatter: actionFormatter
		}, {
			field: 'protoName',
			title: '删除',
			width: 120,
			align: 'center',
			valign: 'middle',
			formatter: actionFormatterD
		},
		],
		onLoadSuccess: function () {
		},
		onLoadError: function () {
			showTips("数据加载失败！");
		},
		onDblClickRow: function (row, $element) {
			var id = row.ID;
			EditViewById(id, 'view');
		},

	});

});

function actionFormatter(value, row, index) {
	var id = value;
	var result = "";
	result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"databaseview('" + id + "')\" title='查看'><span class='feather-search'></span></a>";

	return result;
}

function actionFormatterE(value, row, index) {
	var id = value;
	var result = "";
	result += "<a href='javascript:;' class='btn btn-xs blue' onclick=\"databaseEditViewById('" + id + "')\" title='编辑'><span class='feather-edit'></span></a>";

	return result;
}

function actionFormatterD(value, row, index) {
	var id = value;

	var result = "";
	result += "<a href='javascript:;' class='btn btn-xs red' onclick=\"DeletedatabaseByIds('" + id + "')\" title='删除'><span class='feather-trash-2'></span></a>";

	return result;
}

//模态框清理
$('#editModal').on('hidden.bs.modal',function () {
	deletedatabaseViewEdit(currentId);
  });

  function deletedatabaseViewEdit(args){
	  //console.log(editmodel[args]);
	  //console.log(editmodel[args].length);
	  var Table = document.getElementById("editView");
	  var rowsNum = 0;
	  for(rowsNum;rowsNum<editmodel[args].length;rowsNum++){

	  NewRow = Table.deleteRow(-1); //添加
	  }
  }


//展示用json
var editmodel = []

var proto_a = [
	{
		"id": 8,
		"protoKey": "高度1",
		"protoValue": "123",
		"autoBak": "/etc/test"
	}
]

var proto_b = [
	{
		"id": 6,
		"protoKey": "高度1",
		"protoValue": "123"
	}
]

var proto_c = [
	{
		"id": 4,
		"protoKey": "高度1",
		"protoValue": "123"
	}
]

var proto_d = [
	{
		"id": 3,
		"protoKey": "高度1",
		"protoValue": "123"
	}
]

editmodel.push(proto_a);
editmodel.push(proto_b);
editmodel.push(proto_c);
editmodel.push(proto_d);

console.log(editmodel);
// //编辑协议字段解析表
// function databaseEditViewById(args) {
// 	$('#editModal').modal('show');
// 	var Table = document.getElementById("editView");
// 	currentId = args;
// 	//console.log(editmodel);
// 	var rowsNum = 0;

// 	for (rowsNum; rowsNum < editmodel[args].length; rowsNum++) {
// 		NewRow = Table.insertRow(); //添加行
// 		//添加列
// 		id = NewRow.insertCell();
// 		key = NewRow.insertCell();
// 		value = NewRow.insertCell();

// 		//属性赋值
// 		id.innerHTML = "<input id = id" + (rowsNum + 1) + " Name=id" + (rowsNum + 1) + " value=" + editmodel[args][rowsNum].id + " class='form-control form-control-sm' type='text' />";
// 		key.innerHTML = "<input id = key" + (rowsNum + 1) + " Name=key" + (rowsNum + 1) + " value=" + editmodel[args][rowsNum].protoKey + " class='form-control form-control-sm' type='text' />";
// 		value.innerHTML = "<input id = value" + (rowsNum + 1) + " Name=value" + (rowsNum + 1) + " value=" + editmodel[args][rowsNum].protoValue + " class='form-control form-control-sm' type='text' />";
// 	}
// }

//编辑模态框清理
$('#myModal').on('hidden.bs.modal',function () {
	$("#databaseView").bootstrapTable('destroy');
  });

  function deletedictViewEdit(args){
      var Table = document.getElementById("databaseView");
      var rowsNum = 0;
      for(rowsNum;rowsNum<editmodel[args].length;rowsNum++){
      NewRow = Table.deleteRow(1); //添加
      }
  }

function databaseview(args) {
	

	$('#myModal').modal('show');

	var a = [{
		"protoName": "proto_a",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 1,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "0"
	},
	{
		"protoName": "proto_a",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 3,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "1"
	},
	{
		"protoName": "proto_a",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 4,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "2"
	},
	{
		"protoName": "proto_a",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 4,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "3"
	},
	]
	//b
	var b = [{
		"protoName": "proto_b",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 1,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "0"
	},
	{
		"protoName": "proto_b",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 3,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "1"
	},
	{
		"protoName": "proto_b",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 4,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "2"
	},
	{
		"protoName": "proto_b",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 4,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "3"
	},
	]
	var c = [{
		"protoName": "proto_c",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 1,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "0"
	},
	{
		"protoName": "proto_c",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 3,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "1"
	},
	{
		"protoName": "proto_c",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 4,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "2"
	},
	{
		"protoName": "proto_c",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 4,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "3"
	},
	]
	var d = [{
		"protoName": "proto_d",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 1,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "0"
	},
	{
		"protoName": "proto_d",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 3,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "1"
	},
	{
		"protoName": "proto_d",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 4,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "2"
	},
	{
		"protoName": "proto_d",
		"expireDate": "2023-07-01 12:00:00",
		"autoBak": "/etc/test",
		"protoData": [
			{
				"id": 4,
				"protoKey": "高度1",
				"protoValue": "123"
			}
		],
		"ID": "3"
	},
	]



	


	var tablelist = []
	tablelist.push(a);
	tablelist.push(b);
	tablelist.push(c);
	tablelist.push(d);
	var proto = tablelist[args];
	
	var field = []

	
	for(i = 0; i < proto.length;i++){
		field.push(proto[i].protoData);
		console.log(field);
	}


	
	tablecolumn = [{
		field: 'protoName',
		title: '协议名称'
	}, {
		field: 'expireDate',
		title: '过期时间'
	}, {
		field: 'autoBak',
		title: '自动备份地址'
	}, keyvalue
	, {
		field: 'protoName',
		title: '删除',
		width: 120,
		align: 'center',
		valign: 'middle',
		formatter: actionFormatterD
	}

]


	
	$("#databaseView").bootstrapTable({
		//url: '',
		data: proto,
		dataType: 'json',
		//method: 'POST',                      //请求方式（*）
		//toolbar: '#toolbar',              //工具按钮用哪个容器
		striped: true,                      //是否显示行间隔色
		cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
		pagination: true,                   //是否显示分页（*）
		sortable: true,                     //是否启用排序
		sortOrder: "asc",                   //排序方式
		sidePagination: "client",           //分页方式：client客户端分页，server服务端分页（*）
		pageNumber: 1,                      //初始化加载第一页，默认第一页,并记录
		pageSize: 10,                     //每页的记录行数（*）
		pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
		search: true,                      //是否显示表格搜索
		strictSearch: true,
		showColumns: true,                  //是否显示所有的列（选择显示的列）
		showRefresh: true,                  //是否显示刷新按钮
		showExport: true,
		Icons: 'glyphicon-export icon-share',
		minimumCountColumns: 1,             //最少允许的列数
		clickToSelect: true,                //是否启用点击选中行
		//height: 500,                      //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
		uniqueId: "name",                     //每一行的唯一标识，一般为主键列
		//showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
		cardView: false,                    //是否显示详细视图
		detailView: false,                  //是否显示父子表
		//得到查询的参数
		queryParams: function (params) {
			//这里的键的名字和控制器的变量名必须一致，这边改动，控制器也需要改成一样的
			var temp = {
				rows: params.limit,                         //页面大小
				page: (params.offset / params.limit) + 1,   //页码
				sort: params.sort,      //排序列名  
				sortOrder: params.order //排位命令（desc，asc） 
			};
			return temp;
		},

		columns: [{
			field: 'protoName',
			title: '协议名称'
		}, {
			field: 'expireDate',
			title: '过期时间'
		}, {
			field: 'autoBak',
			title: '自动备份地址'
		}, keyvalue
		, {
			field: 'protoName',
			title: '删除',
			width: 120,
			align: 'center',
			valign: 'middle',
			formatter: actionFormatterD
		},
		],
		onLoadSuccess: function () {
			
		},
		onLoadError: function () {
			showTips("数据加载失败！");
		},
		onDblClickRow: function (row, $element) {
			var id = row.ID;
			EditViewById(id, 'view');
		},

	});
}